﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Entities;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class RubroDAL : DBController
    {
        public RubroDAL()
        { 
        
        }

        /// <summary>
        /// Funcion que devuelve los rubros activos
        /// </summary>
        /// <returns></returns>
        public List<RubroEntity> GetRubros()
        {
            try
            {
                List<RubroEntity> rubros = new List<RubroEntity>();
                using (SqlConnection conn = this.OpenConn())
                {

                    SqlDataReader dr;

                    SqlCommand dCmd = new SqlCommand("MARAVILLA_SQL.spGetRubros", conn);

                    dCmd.CommandText = "MARAVILLA_SQL.spGetRubros";

                    dCmd.CommandType = CommandType.StoredProcedure;


                    // dCmd.ExecuteNonQuery();
                    dr = dCmd.ExecuteReader();
                    dCmd.Dispose();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            RubroEntity rubro = new RubroEntity();
                            rubro.IntIdRubro = (int)dr.GetValue(0);
                            rubro.VarNombre = (string)dr.GetValue(1);
                            rubro.BitIsDeleted = (bool)dr.GetValue(2);

                            rubros.Add(rubro);
                        }
                    }
                }
                return rubros;

            }catch(Exception ex){
                throw ex;
            }
        }
    }
}
